﻿using AutoMapper;
using SXICE.Core.Domains;
using SXICE.Core.Helpers;
using SXICE.Core.Infrastructure;
using SXICE.Core.Models;
using SXICE.Core.Models.DTOs;
using SXICE.IRepository;
using SXICE.IService.Models;
using SXICE.Service.Models;
using System;
using System.Linq;

namespace SXICE.Service
{
    /// <summary>
    /// Mapper配置文件
    /// </summary>
    public class MapperProfile : Profile, IMapperRegister
    {
        public MapperProfile()
        {
            #region Base

            CreateMap(typeof(ReturnResult<>), typeof(ReturnResult<>));
            CreateMap(typeof(PageListQuery<>), typeof(PageListQuery<>));
            CreateMap(typeof(ReturnPageListResult<>), typeof(ReturnPageListResult<>));

            #endregion

            #region Doctor

            CreateMap<ChangePasswordDTO, Doctor>().ForMember(c => c.RealName, opt => opt.MapFrom(c => c.OldPassword));

            #endregion

            #region Users

            CreateMap<DoctorDTO, Doctor>();
            CreateMap<Doctor, DoctorDTO>().ForMember(c => c.Password, opt => opt.Ignore());

            #endregion
        }

        public void Register(IMapperConfigurationExpression mapperConfiguration)
        {
            mapperConfiguration.AddProfile<MapperProfile>();
        }
    }
}
